﻿using System;
using TheOutLetLibrary.Dominio;
using System.Data.OleDb;

namespace TheOutLetLibrary.Infraestrutura {

    public class Accessk_addressshippingDAO : BaseDAO, IGenericDAO<k_address> {

        public Accessk_addressshippingDAO(OleDbTransaction transacao)
            : base(transacao) {
        }

        public int Inclua(k_address entity) {

            OleDbCommand comando = GetCommand();

            comando.CommandText =
                " INSERT INTO k_shipping (" +
                " NR_PEDIDO, id, contactName, addressName, address, " +
                " [number], province, complement, city, state, zipcode) " +
                " VALUES (" +
                " @NR_PEDIDO, @id, @contactName, @addressName, @address, " +
                " @number, @province, @complement, @city, @state, @zipcode) ";

            comando.Parameters.Add("@NR_PEDIDO", OleDbType.Integer).Value = entity.NR_PEDIDO;
            comando.Parameters.Add("@id", OleDbType.VarChar).Value = entity.id;
            comando.Parameters.Add("@contactName", OleDbType.VarChar).Value = entity.contactName;
            comando.Parameters.Add("@addressName", OleDbType.VarChar).Value = entity.addressName;
            comando.Parameters.Add("@address", OleDbType.VarChar).Value = entity.address;
            comando.Parameters.Add("@number", OleDbType.VarChar).Value = entity.number;
            comando.Parameters.Add("@province", OleDbType.VarChar).Value = entity.province;
            comando.Parameters.Add("@complement", OleDbType.VarChar).Value = entity.complement == null ? "" : entity.complement;
            comando.Parameters.Add("@city", OleDbType.VarChar).Value = entity.city;
            comando.Parameters.Add("@state", OleDbType.VarChar).Value = entity.state;
            comando.Parameters.Add("@zipcode", OleDbType.VarChar).Value = entity.zipcode;
            comando.ExecuteNonQuery();

            comando.CommandText = "SELECT @@IDENTITY";
            entity.COD = Convert.ToInt32(comando.ExecuteScalar());
            return entity.COD;

        }

        public k_address Ache(int Id) {
            throw new NotImplementedException();
        }
    }
}
